from multiprocessing import Pool
from random import randint
import time

def f(x):
    time.sleep(randint(3, 6))
    print x*x

if __name__ == '__main__':
    p = Pool(4)
    for i in range(8):
        p.apply_async(f, (i,))
    print "pool end."
    p.close()
    p.join()
    print "main exit"
